<%@page contentType="text/html; charset=UTF-8" import="com.pub.database.*,java.util.*" %>
<% response.setContentType("text/html;charset=UTF-8"); request.setCharacterEncoding("UTF-8"); %>
<% response.setHeader("Cache.Control","no-cache"); response.setHeader("Pragma","no-cache"); response.setDateHeader("Expires",0);%>
<jsp:useBean id="DataViewForm" scope="request" class="com.pub.database.DataViewForm"/>
<!-- 以下為DataView 共用設定 -->
<jsp:setProperty name="DataViewForm" property="submitMethod" value="POST"/>
<jsp:setProperty name="DataViewForm" property="pageRowCount" value="10"/>
<jsp:setProperty name="DataViewForm" property="nowPageNum"/>
<jsp:setProperty name="DataViewForm" property="dataViewAction"/>
<jsp:setProperty name="DataViewForm" property="filterCol"/>
<jsp:setProperty name="DataViewForm" property="filterValue"/>
<jsp:setProperty name="DataViewForm" property="dvOrderByFields"/>
<jsp:setProperty name="DataViewForm" property="dvOrderBySeq"/>
<!-- DataView 設定結束 -->
<%
  String strDBAlias = (request.getParameter("DB_ALIAS")==null ?"" :request.getParameter("DB_ALIAS"));
  if(strDBAlias.equals("")){
    return;
  }
  QueryBean gqbnDAO = new QueryBean(strDBAlias,false,"utf-8","utf-8");

  DataView dataView=null;
  dataView = new DataView(gqbnDAO);


  String strModel = request.getParameter("find_model")==null ? "":request.getParameter("find_model");



  StringBuffer stbCondition = new StringBuffer();
  StringBuffer stbPageActionURI = new StringBuffer();
  stbPageActionURI.append(request.getRequestURI());
  stbPageActionURI.append("?DB_ALIAS=");
  stbPageActionURI.append(strDBAlias==null ? "" : strDBAlias);
  stbPageActionURI.append("&find_model=");
  stbPageActionURI.append(strModel==null ? "" : strModel);

  DataViewForm.setTablesList("pma_master");

  stbCondition.append("1=1");

  if(strModel!=null && !strModel.equals("")){
    stbCondition.append(" and master_model like '%");
    stbCondition.append(strModel);
    stbCondition.append("%'");
  }


  DataViewForm.setSQLCondition(stbCondition.toString());
  DataViewForm.setOrderByFields("master_model");
  DataViewForm.setOrderBySeq("asc");
  DataViewForm.setGroupBy(null);
  DataViewForm.setHaving(null);

  ArrayList<Hashtable<String,Object>> laltColRelation = new ArrayList<Hashtable<String,Object>>();
  Hashtable<String,Object> lhtColRelationDetail = new Hashtable<String,Object>();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "'' as CHECKBOX");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'SELECT'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "INPUT");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML, "<INPUT TYPE=\"RADIO\" onclick=\"javascript:retVal('%sn%')\" name=\"sel\" value=");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE, "'none'");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='10%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();

  lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "MASTER_MODEL");
  lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'MODEL'");
  lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "INPUT");
  lhtColRelationDetail.put(dataView.STR_FIELD_HTML, "<INPUT type='text' readonly class='input_noborder' name='model%sn%' value=");
  lhtColRelationDetail.put(dataView.STR_FIELD_VALUE,"MASTER_MODEL");
  lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"width='100%' align='center'");

  laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
  lhtColRelationDetail.clear();


  DataViewForm.setColRelationUseArrayList(laltColRelation);//將欄位相關設定殖入ActionForm
  DataViewForm.setJumpPageButtonShow(false);//是否要秀出上下頁按鈕
  DataViewForm.setPageBtnOnTop(false);//將buttonandrowsinfo秀在頂端
  DataViewForm.setPageBtnOnButtom(true);//將buttonandrowsinfo秀在底端
  DataViewForm.setFilterShow(false);//是否要秀出過濾選擇欄位
  DataViewForm.setJumpPageShow(true);//是否要秀出跳頁下拉式選單
  DataViewForm.setRowsInfoShow(true);//是否要秀出筆數資訊
  DataViewForm.setRowPageShow(false);//是否要秀出每頁筆數控制欄
  DataViewForm.setExcelShow(false);//是否要秀出轉Excelbutton
  DataViewForm.setOrderEnable(false);//是否要提供排序點選功能
  DataViewForm.setShowHeaderWhenNoData(true);//當ResultSet無資料是否要秀Header
  DataViewForm.setAddNewShow(false);//是否秀出新增鈕

  DataViewForm.setTableHeaderHtml("class='td_head_grid' align='center' width='680px'");
  //設定上一頁與下一頁按鈕的formaction(通常為母頁即本頁)
  DataViewForm.setPageActionURI(stbPageActionURI.toString());
  String strResult="";
  try{
    strResult=dataView.getOutputDataView(DataViewForm);
  }
  catch(Exception e){
    e.printStackTrace();
  }
  finally{

    try{gqbnDAO.close();gqbnDAO=null;}catch(Exception e){e.printStackTrace();}
 }

%>
<html>
<head>
<title>MODEL Pick Up Window</title>
<LINK HREF="/PUBPAGE/general/workflow.css" REL="STYLESHEET" TYPE="TEXT/CSS"/>
<base target='_self'/>
<script language="javascript" type="">
      // Return values when exit  value: Dept No,Dept Name
      function retVal(v_sn){
         window.returnValue=document.all.item('model' + v_sn).value;
         window.close();
      }
</script>
</head>
<body>
  <form action="<%=request.getRequestURI()%>" method="POST">
  <input type="hidden" name="DB_ALIAS" value="<%=strDBAlias%>">
    <table>
      <tr>
         <th>MODEL：</th>
         <td class="td_content"><input type="text" name="find_model" size="10" maxlength="30" class="input" value="<%=strModel%>" />　</td>
         <td><input type="submit"  value="Search" class="button b_normal"/>　</td>
      </tr>
    </table>
  </form>
<%=strResult==null ? "":strResult%>
</body>
</html>
